use tokio::sync::broadcast;

use crate::utils::UninitCell;

pub struct OnlineInfo {
    tx: broadcast::Sender<()>,
    _rx: broadcast::Receiver<()>,
}


pub static ONLINE_INFO: UninitCell<OnlineInfo> = UninitCell::empty();

impl OnlineInfo {
    pub fn new() -> Self {
        let (tx, rx) = broadcast::channel(64);
        Self {
            tx,
            _rx: rx,
        }
    }

    pub fn subscribe(&self) -> broadcast::Receiver<()> {
        self.tx.subscribe()
    }

    pub fn notify(&self) {
        _ = self.tx.send(());
    }
}
